<%--
  Created by IntelliJ IDEA.
  User: 86134
  Date: 2024/9/29
  Time: 9:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>花卉管理系统</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }

        h2 {
            margin-bottom: 10px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }

        th, td {
            border: 1px solid #ddd;
            padding: 10px;
            text-align: center;
        }

        th {
            background-color: #f2f2f2;
            font-weight: bold;
        }

        tr:nth-child(even) {
            background-color: #f9f9f9;
        }

        form {
            display: inline-block;
        }

        button, input[type="submit"], input[type="reset"] {
            padding: 5px 10px;
            margin-left: 5px;
        }

        label {
            display: inline-block;
            width: 100px;
            text-align: right;
            margin-right: 10px;
        }

        input[type="text"], input[type="number"] {
            padding: 5px;
            width: 200px;
        }
    </style>
</head>
<body>

<h2>花卉列表</h2>
<table>
    <thead>
    <tr>
        <th>ID</th>
        <th>名称</th>
        <th>别名</th>
        <th>属性</th>
        <th>价格</th>
        <th>产地</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach var="flower" items="${flowers}">
        <tr>
            <td>${flower.id}</td>
            <td>${flower.name}</td>
            <td>${flower.anothername}</td>
            <td>${flower.property}</td>
            <td>${flower.price}</td>
            <td>${flower.production}</td>
        </tr>
    </c:forEach>
    </tbody>
</table>

<h2>添加新花卉</h2>
<form action="${pageContext.request.contextPath}/flowers" method="post" id="addFlowerForm">
    <label for="name">名称</label>
    <input type="text" id="name" name="name" placeholder="请输入名称" required>
    <label for="anothername">别名</label>
    <input type="text" id="anothername" name="anothername" placeholder="请输入别名">
    <label for="property">属性</label>
    <input type="text" id="property" name="property" placeholder="请输入属性">
    <label for="price">价格</label>
    <input type="number" id="price" name="price" placeholder="请输入价格" step="0.01" required>
    <label for="production">产地</label>
    <input type="text" id="production" name="production" placeholder="请输入产地" required>
    <input type="submit" value="提交">
    <input type="reset" value="重置">
</form>

<script>
    $(document).ready(function () {
        $('#addFlowerForm').submit(function (event) {
            event.preventDefault();
            var name = $('#name').val();
            var price = $('#price').val();
            var production = $('#production').val();

            if (!name || !price || !production) {
                alert('名称、价格和产地不能为空');
                return;
            }

            $(this).unbind('submit').submit();
        });
    });
</script>

</body>
</html>


